<template>
  <div class="app-container">

    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.checktime"
        type="daterange"
        range-separator="至"
        class="filter-item"
        style="width:300px"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>

      <el-cascader :options="city" class="filter-item w-200" style="width:300px" clearable filterable
                   placeholder="选择区域" :props="{ expandTrigger: 'hover', checkStrictly: true }" v-model="listQuery.ltype"
      ></el-cascader>

      <el-input
        v-model="listQuery.u_name"
        placeholder="或单独输入单位名"
        clearable
        class="filter-item w-200"
      />

      <el-select v-model="listQuery.evaluate_all" class="filter-item w-200" placeholder="评分筛选" clearable>
        <el-option
          v-for="(item,idx) in ['好评','差评','未评分']"
          :label="item"
          :value="idx+1"
        >
        </el-option>
      </el-select>
      <el-button-group class="filter-item">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="fetchData"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>
      </el-button-group>

    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      height="100%"
      class="table-container"
      highlight-current-row
      @sort-change="sortChange"
    >


      <el-table-column
        width="200"
        label="单位"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.user_name }}
        </template>
      </el-table-column>
      <el-table-column
        width="200"
        label="数量"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.count }}
        </template>
      </el-table-column>

      <el-table-column
        label="更多信息"
        width="135"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-more"
            size="mini"
            @click="goWid(scope.row.wid)"
          />
        </template>
      </el-table-column>
    </el-table>


  </div>
</template>
<style>
.fontSize {
  font-size: 14px;
}

.rowpadding {
  padding: 20px 0 !important;
}

.headerClass {
  background: #409EFF;
}
</style>
<script>
import { getReply } from '@/api/rank'
import { getCity } from '@/api/user'

let id = 0
export default {
  data() {
    return {
      total: 0,
      list: [],
      listLoading: false,
      listQuery: {
        checktime: [new Date(new Date().getFullYear(), new Date().getMonth(), 1).toLocaleDateString('fr-CA'), new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0, 23, 59, 59).toLocaleDateString('fr-CA')],
        ltype: '',
        evaluate_all: '',
        u_name:'',
      },
      baseData: [],
      loading: false,
      citys: []
    }
  },
  created() {
    this.WzParams()
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.customerReportDateTable.doLayout()
    })
  },
  methods: {
    WzParams() {
      let citys = localStorage.getItem('citys'), citys_ary = []
      if (!citys) {
        getCity().then(response => {
          citys_ary = response.data.city
          localStorage.setItem('citys', JSON.stringify(this.city))
        })
      } else {
        citys_ary = JSON.parse(citys)
      }
      citys_ary.splice(0, 1)
      citys_ary.splice(0, 1)
      this.city = citys_ary
    },
    refresh() {
      this.listQuery = {
        checktime: [new Date(new Date().getFullYear(), new Date().getMonth(), 1).toLocaleDateString('fr-CA'), new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0, 23, 59, 59).toLocaleDateString('fr-CA')],
        ltype: '',
        evaluate_all: '',
        u_name:'',
      }
      this.CountType()
    },

    fetchData() {
      this.listLoading = true
      getReply(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data
      }).catch(e=>{
        this.listLoading = false
      })
    }
  }
}
</script>
